home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / oasis / oasis1-1.lha / oasis-1.1 / bind.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  5KB  |  140 lines

  1. /*==========================================================================*
  2.     Oasis Alpha Version 1.1               (C) Copyright 1992 Fah-Chun Cheong
  3.     Revised: 5/1/92 by: fcc@eecs.umich.edu    and The University of Michigan
  4.     ------------------------------------------------------------------------
  5.     Permission to use, copy, modify, distribute, sell and resell Oasis Alpha
  6.     software and its documentation for any purpose and without fee is hereby
  7.     granted, provided that the authorship be appropriately credited and
  8.     acknowledged, and that the above copyright notice appear in all copies
  9.     and both the copyright notice and this permission notice appear in
  10.     supporting documentation. The author makes no representations about the
  11.     suitability of this software for any purpose. It is provided "as is"
  12.     without express or implied warranty. Oasis Alpha is free, caveat emptor!
  13.     ------------------------------------------------------------------------
  14.     To request Oasis Alpha source code:   oasis-alpha-request@eecs.umich.edu
  15.     To enroll in the mailing list:        oasis-alpha-request@eecs.umich.edu
  16.     To send bug reports:                  oasis-alpha-bugs@eecs.umich.edu
  17.     To discuss openly all matters Oasis:  oasis-alpha@eecs.umich.edu
  18.  *==========================================================================*/
  19. #include                "gener.h"
  20.  
  21. #define SNO             10
  22. static  char           *stab[SNO] = {
  23.                         "$root",
  24.                         "$handle",
  25.                         "$listc",
  26.                         "$listi",
  27.                         "$listf",
  28.                         "$listp",
  29.                         "$arrayc",
  30.                         "$arrayi",
  31.                         "$arrayf",
  32.                         "$arrayp"
  33. };
  34.  
  35. int     read_program(name, bufp)
  36. char   *name;
  37. char  **bufp;
  38. {
  39.         char    name_p[1024];
  40.         int     fd;
  41.         int     size;
  42.  
  43.         sprintf(name_p, "%s.p", name);
  44.         if ((fd = open(name_p, 0)) < 0) {
  45.             perror("opening program file");
  46.             exit(-1);
  47.         }
  48.         size  = lseek(fd, 0L, 2);
  49.         *bufp = (char *) malloc(size + 3);
  50.         lseek(fd, 0L, 0);
  51.         read(fd, *bufp + 1, size);
  52.         (*bufp)[0]        = '\n';
  53.         (*bufp)[size + 1] = '\n';
  54.         (*bufp)[size + 2] = '\0';
  55.         close(fd);
  56.         fprintf(stderr, "\"%s\":\t%8d bytes read.\n", name_p, size);
  57.         return size + 3;
  58. }
  59.  
  60. int     write_package(name, bufv, argc)
  61. char   *name;
  62. char  **bufv;
  63. int     argc;
  64. {
  65.         char    name_t[1024];
  66.         int     fd;
  67.         int     size = 0;
  68.         int     i;
  69.  
  70.         sprintf(name_t, "%s.t", name);
  71.         if ((fd = creat(name_t, 0600)) < 0) {
  72.             perror("creating transcode package");
  73.             exit(-1);
  74.         }
  75.         for (i = 1; i < argc - 1; i++)
  76.             size += write(fd, bufv[i], strlen(bufv[i]));
  77.         close(fd);
  78.         fprintf(stderr, "\"%s\":\t%8d bytes written.\n", name_t, size);
  79.         return size;
  80. }
  81.  
  82. void    main(argc, argv)
  83. int     argc;
  84. char   *argv[];
  85. {
  86.         char  **tbufv = (char **) calloc(argc, sizeof(char **));
  87.         int     i, j, k;
  88.  
  89.         if (argc < 3) {
  90.             fprintf(stderr, "Usage: %s program [...] package\n", argv[0]);
  91.             exit(-1);
  92.         }
  93.         init_gen(SNO, stab);
  94.         for (i = 1; i < argc - 1; i++) {
  95.             char *pbuf;
  96.             int   size = read_program(argv[i], &pbuf);
  97.             tbufv[i]   = (char *) malloc(size * 16);
  98.             generate(pbuf, tbufv[i]);
  99.             free(pbuf);
  100.         }
  101.         for (i = 0; i < pno; i++)
  102.             for (k = ptab[i].isa; k != 0; k = ptab[k].isa)
  103.                 for (j = ptab[k].mno; --j >= 0;)
  104.                     if (ptab[i].mtab[j] == 0)
  105.                         ptab[i].mtab[j] = ptab[k].mtab[j];
  106.         emit0 (".data");
  107.         emit0 (".align");
  108.         globl ("cno");
  109.         word  (pno);
  110.  
  111.         globl ("ctab");
  112.         for (i = 0;  i < 10;  i++) word(0);
  113.         for (;       i < pno; i++) addrC(i);
  114.  
  115.         globl ("dtab");
  116.         for (i = 0;  i < 10;  i++) word(0);
  117.         for (;       i < pno; i++) addrM(i);
  118.         for (i = 10; i < pno; i++) {
  119.             labelM(i);
  120.             if (ptab[i].mno == -1)
  121.                 err1("Undefined program `%s'.\n", ptab[i].name);
  122.             else if (ptab[i].mtab[0] == 0) word(0);
  123.             else addrL(ptab[i].mtab[0], 0);
  124.             for (j = 1; j < ptab[i].mno; j++) {
  125.                 addrL(ptab[i].mtab[j], j);
  126.                 if (ptab[i].mtab[j] == 0)
  127.                     err2("Undefined method %s::%d.\n", ptab[i].name, j);
  128.             }
  129.         }
  130.         globl ("stab");
  131.         for (i = 0; i < pno; i++) addrS(i);
  132.         for (i = 0; i < pno; i++) {
  133.             labelS(i);
  134.             emit0L(".ascii", ptab[i].name);
  135.         }
  136.         emit0 (".align");
  137.         write_package(argv[argc - 1], tbufv, argc);
  138. }
  139.  
  140.